/******************************************************************************
 * * sms_setting.c - implementation of sms setting functions
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "sms_include.h"

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Setting(lv_obj_t *pBtn,lv_event_t event)
{
    // sms setting function
    // create Message_Setting chart
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *pSetting   = NULL;
    UI_Button_Desc_t           *ButtonList = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pSetting = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(pSetting, 0, sizeof(UI_Normal_List_Only_Desc_t));

    ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 3);
    Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * 3);

    g_MsgGlobalCtrl.CurOpenBox = MSG_SETTING;
    g_MsgGlobalCtrl.pChart     = pSetting;

    pSetting->TitleBar.TxtId      = PHONE_TEXT_ID_SMS_SETTING;
    pSetting->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pSetting->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    pSetting->List.ListButtonCnt = 3;
    pSetting->List.Index         = 0;
    pSetting->List.ButtonList    = ButtonList;

    ButtonList[0].ButtonIndex = 0;
    ButtonList[0].TxtId       = PHONE_TEXT_ID_INFO_SER;
    ButtonList[0].ReleaseFun  = Sms_Setting_Sending_Profile;
    ButtonList[0].Valid       = true;
    ButtonList[1].ButtonIndex = 1;
    ButtonList[1].TxtId       = PHONE_TEXT_ID_DELIVERY_REP;
    ButtonList[1].ReleaseFun  = Sms_Setting_Delivery_Report;
    ButtonList[1].Valid       = true;
    ButtonList[2].ButtonIndex = 2;
    ButtonList[2].TxtId       = PHONE_TEXT_ID_NSCREENING;
    ButtonList[2].ReleaseFun  = Sms_Setting_No_Scrn;
    ButtonList[2].Valid       = true;

    pSetting->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pSetting->BtnBar.ButtonR.Valid = true;

    pSetting->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    pSetting->BtnBar.ButtonM.Valid = true;

    pSetting->KeyFunc = Sms_Setting_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Setting_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;     // temp
    FuncList.OnRestoreState = Sms_Common_Restore;  // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_SETTING, &FuncList, (void *)pSetting);
} /* Sms_Setting */

/**
 * Common Process UI destroy event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Sms_Setting_Destory(VOID *pDesc)
{
    UI_Normal_List_Only_Desc_t *pInput = pDesc;

    Hal_Mem_Free(pInput->List.ButtonList);
    pInput->List.ButtonList = NULL;
    Sms_Common_All_Global_Destory(pDesc);
}

/**
 * entry of message APP
 * param (in) lv_obj_t * obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val
 * return  UINT8
 */
UINT8 Sms_Setting_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
    }
    return(Result);    // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  void
 */
void Sms_Setting_Sending_Profile(lv_obj_t *pBtn,lv_event_t event)
{
    // sms setting list Sending Profile call back function
    // create Messages_Sim_Selection chart
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *pSendPro   = NULL;
    UI_Button_Desc_t           *ButtonList = NULL;
    SMS_SIM_STATUS             SimStatus   = SMS_NO_SIM_PRESENT;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pSendPro = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(pSendPro, 0, sizeof(UI_Normal_List_Only_Desc_t));

    g_MsgGlobalCtrl.pChart = pSendPro;

    pSendPro->TitleBar.TxtId      = PHONE_TEXT_ID_SIM_SEL;
    pSendPro->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pSendPro->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    SimStatus = Sms_Get_Sim_Status();
    if (SMS_SIM1_PRESENT == (SimStatus & SMS_SIM1_PRESENT))
    {
        pSendPro->List.ListButtonCnt++;
    }
    if (SMS_SIM2_PRESENT == (SimStatus & SMS_SIM2_PRESENT))
    {
        pSendPro->List.ListButtonCnt++;
    }
    if (pSendPro->List.ListButtonCnt)
    {
        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * pSendPro->List.ListButtonCnt);
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * pSendPro->List.ListButtonCnt);
        pSendPro->List.Index      = 0;
        pSendPro->List.ButtonList = ButtonList;

        if (SMS_BOTH_SIM_PRESENT == SimStatus)
        {
            ButtonList[0].ButtonIndex = 0;
            ButtonList[0].TxtId       = PHONE_TEXT_ID_SIM1;
            ButtonList[0].SymbolId1   = SYMBOL_SIM1;
            ButtonList[0].Valid       = true;
            ButtonList[0].ReleaseFun  = Sms_Setting_Sim_Select;

            ButtonList[1].ButtonIndex = 1;
            ButtonList[1].TxtId       = PHONE_TEXT_ID_SIM2;
            ButtonList[1].SymbolId1   = SYMBOL_SIM2;
            ButtonList[1].Valid       = true;
            ButtonList[1].ReleaseFun  = Sms_Setting_Sim_Select;
        }
        else if (SMS_SIM1_PRESENT == SimStatus)
        {
            ButtonList[0].ButtonIndex = 0;
            ButtonList[0].TxtId       = PHONE_TEXT_ID_SIM1;
            ButtonList[0].SymbolId1   = SYMBOL_SIM1;
            ButtonList[0].Valid       = true;
            ButtonList[0].ReleaseFun  = Sms_Setting_Sim_Select;
        }
        else if (SMS_SIM2_PRESENT == SimStatus)
        {
            ButtonList[0].ButtonIndex = 0;
            ButtonList[0].TxtId       = PHONE_TEXT_ID_SIM2;
            ButtonList[0].SymbolId1   = SYMBOL_SIM2;
            ButtonList[0].Valid       = true;
            ButtonList[0].ReleaseFun  = Sms_Setting_Sim_Select;
        }
    }

    pSendPro->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pSendPro->BtnBar.ButtonR.Valid = true;

    if(SimStatus != SMS_NO_SIM_PRESENT)
    {
        pSendPro->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
        pSendPro->BtnBar.ButtonM.Valid = true;
    }
    else
    {
        pSendPro->BtnBar.ButtonM.Valid = false;
    }

    pSendPro->KeyFunc = Sms_Create_Opt_Handle;    // common

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Create_Send_To_Many_Create;
    FuncList.OnDestroy      = Sms_List_Only_Common_Destory;   // temp
    FuncList.OnSaveState    = Sms_Common_Save;                // temp
    FuncList.OnRestoreState = Sms_Create_Send_To_Many_Create; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_SIM_SELECTION, &FuncList, (void *)pSendPro);
} /* Sms_Setting_Sending_Profile */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Setting_Sim_Select(lv_obj_t *pBtn,lv_event_t event)
{
    // sms setting Sending Profile sim selection call back function
    // create Messages_Centre_No. chart with smsc number
    Nav_Func_List_t                   FuncList;
    UI_Normal_NoTitle_Label_Ta_Desc_t *pPhoneNum = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pPhoneNum = (UI_Normal_NoTitle_Label_Ta_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));
    Hal_Mem_Set(pPhoneNum, 0, sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));

    g_MsgGlobalCtrl.pChart = pPhoneNum;

    g_MsgGlobalCtrl.CurrSimId = (MMI_MODEM_SIM_ID)pBtn->user_data.user_num;    // store the sim id

    pPhoneNum->ContLabelTl.LabelAlign  = LV_ALIGN_IN_TOP_LEFT;
    pPhoneNum->ContLabelTl.TxtId       = LV_LANG_TXT_ID_NONE;
    pPhoneNum->ContLabelTl.SymbolAlign = LV_LABEL_ALIGN_CENTER;
    pPhoneNum->ContLabelTl.SymbolId    = LV_SYMBOL_EDIT; // temp

    pPhoneNum->ContLabelTr.LabelAlign = LV_ALIGN_IN_TOP_RIGHT;
    pPhoneNum->ContLabelTr.TxtId      = LV_LANG_TXT_ID_NONE;
    pPhoneNum->ContLabelTr.TxtAlign   = LV_LABEL_ALIGN_RIGHT;

    pPhoneNum->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_MID;
    pPhoneNum->ContLabel.TxtId      = PHONE_TEXT_ID_PHONE_NUM;
    pPhoneNum->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pPhoneNum->ContTa.TaCursorHide  = FALSE;
    pPhoneNum->ContTa.TaTxt         = NULL;

    pPhoneNum->ButtonCont.ButtonL.TxtId = PHONE_TEXT_ID_BACK;
    pPhoneNum->ButtonCont.ButtonL.Valid = true;

    pPhoneNum->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_SEARCH;
    pPhoneNum->ButtonCont.ButtonM.Valid = true;

    pPhoneNum->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_CLEAR;
    pPhoneNum->ButtonCont.ButtonR.Valid = true;

    pPhoneNum->KeyFunc = Sms_Setting_Phone_Num_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_NoTitle_Label_Ta_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Setting_Sim_Select_On_Create;
    FuncList.OnDestroy      = Sms_Common_Destory;               // temp
    FuncList.OnSaveState    = Sms_Common_Save;                  // temp
    FuncList.OnRestoreState = Sms_Setting_Sim_Select_On_Create; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_CENTRE_NUM, &FuncList, (void *)pPhoneNum);
} /* Sms_Setting_Sim_Select */

/**
 * Common Process UI Create event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Sms_Setting_Sim_Select_On_Create(VOID *pDesc)
{
    UINT32                            i = 0;
    INT8                              Temp1[MSG_TEXT_INPUT_MAX_LEN];
    UI_Normal_NoTitle_Label_Ta_Desc_t *pPhoneNum = NULL;

    g_MsgGlobalCtrl.pChart = pDesc;
    pPhoneNum              = g_MsgGlobalCtrl.pChart;

#if 0
    if (MMI_MODEM_SIM_1 == g_MsgGlobalCtrl.CurrSimId)
    {
        lv_textarea_set_text(pPhoneNum->ContTa.TextArea, g_MsgGlobalCtrl.Smsc[0].pSmsc);
    }
    else
    {
        lv_textarea_set_text(pPhoneNum->ContTa.TextArea, g_MsgGlobalCtrl.Smsc[1].pSmsc);
    }


    lv_label_set_text((lv_obj_t *)pPhoneNum->ButtonCont.ButtonM.Button->child_ll.head, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_OK));
#endif
    lv_textarea_set_accepted_chars(pPhoneNum->ContTa.TextArea, g_AcceptInputNum);
    lv_textarea_set_max_length(pPhoneNum->ContTa.TextArea, MSG_INPUT_PHONE_NUM_MAX_LEN);

    if (NULL != g_MsgGlobalCtrl.pContact)
    {
        i = strlen(g_MsgGlobalCtrl.pContact);
        lv_textarea_set_text(pPhoneNum->ContTa.TextArea, g_MsgGlobalCtrl.pContact);
    }
    sprintf(Temp1, "%d", MSG_INPUT_PHONE_NUM_MAX_LEN - i);
    lv_label_set_text(pPhoneNum->ContLabelTr.Label, Temp1);
    Ime_Set_GetCharLen_Func(Sms_Phone_Num_Input_char_Process);
    Ime_Set_Mode(LV_IME_MODE_NUM);
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  UINT8
 */
UINT8 Sms_Setting_Phone_Num_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8                             Result = 0;
    UINT32                            i      = 0;
    INT8                              *pTemp;
    INT8                              Temp[MSG_TEXT_INPUT_MAX_LEN];
    UI_Normal_NoTitle_Label_Ta_Desc_t *pPhoneNum = g_MsgGlobalCtrl.pChart;    // temp

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        switch (key_val)
        {
        case KEY_0:
        case KEY_1:
        case KEY_2:
        case KEY_3:
        case KEY_4:
        case KEY_5:
        case KEY_6:
        case KEY_7:
        case KEY_8:
        case KEY_9:
        case KEY_ASTERISK:
            pTemp = (INT8 *)lv_textarea_get_text(obj);            // temp
            i     = strlen(pTemp);
            if (i < MSG_INPUT_PHONE_NUM_MAX_LEN)
            {
                sprintf(Temp, "%d", MSG_INPUT_PHONE_NUM_MAX_LEN - i - 1);
            }
            else
            {
                sprintf(Temp, "%d", 0);
                Result = 1;
            }
            lv_label_set_text(pPhoneNum->ContLabelTr.Label, Temp);
            lv_label_set_text((lv_obj_t *)pPhoneNum->ButtonCont.ButtonM.Button->child_ll.head, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_OK));
            break;

        case KEY_SOFTRIGHT:
            lv_textarea_del_char(obj);
            pTemp = (INT8 *)lv_textarea_get_text(obj);
            i     = strlen(pTemp);
            if (0 == i)
            {            // clear all
                lv_label_set_text((lv_obj_t *)pPhoneNum->ButtonCont.ButtonM.Button->child_ll.head, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_SEARCH));
            }
            sprintf(Temp, "%d", MSG_INPUT_PHONE_NUM_MAX_LEN - i);
            lv_label_set_text(pPhoneNum->ContLabelTr.Label, Temp);
            Result = 1;
            break;

        case KEY_SOFTLEFT:
            Nav_Back(ACT_ID_ANY);
            Result = 1;
            break;

        case KEY_OK:
            pTemp = (INT8 *)lv_textarea_get_text(obj);        // temp
            i     = strlen(pTemp);
            if (i)
            {            // ok
                Hal_Mem_Free(g_MsgGlobalCtrl.pContact);
                g_MsgGlobalCtrl.pContact = NULL;
                g_MsgGlobalCtrl.pContact = Hal_Mem_Alloc(MSG_INPUT_PHONE_NUM_MAX_LEN + 1);
                Hal_Mem_Set(g_MsgGlobalCtrl.pContact, 0, MSG_INPUT_PHONE_NUM_MAX_LEN + 1);
                strcpy(g_MsgGlobalCtrl.pContact, pTemp);
                Sms_Setting_Phone_Num_OK();
            }
            else
            {            // search
                g_MsgGlobalCtrl.SelContactType = IF_CONTACTS_SMS_SEL_ONE_CONTACT;
                Contacts_Select_Contact_Req(IF_CONTACTS_SMS_SEL_ONE_CONTACT);
            }
            Result = 1;
            break;

        case KEY_END:
            Nav_Home(ACT_ID_ANY);
            Result = 1;
            break;

        default:
            break;
        } /* switch */
    }
    else if (KEY_LONGPRESS == key_sta)
    {    // clear all
        if (KEY_SOFTRIGHT == key_val)
        {
            lv_textarea_set_text(obj, "");
            sprintf(Temp, "%d", MSG_INPUT_PHONE_NUM_MAX_LEN);
            lv_label_set_text(pPhoneNum->ContLabelTr.Label, Temp);
            lv_label_set_text((lv_obj_t *)pPhoneNum->ButtonCont.ButtonM.Button->child_ll.head, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_SEARCH));
        }
    }
    return(Result);   // temp
} /* Sms_Setting_Phone_Num_Handle */

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Setting_Phone_Num_OK(VOID)
{
    UINT32                   i = 0;
    Nav_Func_List_t          FuncList;
    UI_Status_Desc_t         *pSendSts    = NULL;
    MMI_Modem_Set_Smsc_Req_t *pSetSmscReq = NULL;
    CB_FUNC                  callback     = Sms_Setting_Phone_Num_OK_Timeout;

    pSendSts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pSendSts, 0, sizeof(UI_Status_Desc_t));

    pSendSts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pSendSts->ContLabel.TxtId      = PHONE_TEXT_ID_CENTRE_NUM_SAVED;
    pSendSts->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pSendSts->ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    pSendSts->ContImg.Img      = SYMBOL_CHECKED;
    pSendSts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pSendSts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_CENTRE_NUM_STATUS, &FuncList, (void *)pSendSts);

    i = strlen(g_MsgGlobalCtrl.pContact);
    if (i)
    {
        pSetSmscReq = (MMI_Modem_Set_Smsc_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Set_Smsc_Req_t));
        Hal_Mem_Set(pSetSmscReq, 0, sizeof(MMI_Modem_Set_Smsc_Req_t));
        pSetSmscReq->pSmsc = Hal_Mem_Alloc(i + 1);
        Hal_Mem_Set(pSetSmscReq->pSmsc, 0, i + 1);
        pSetSmscReq->SimId = g_MsgGlobalCtrl.CurrSimId;
        Hal_Mem_Free(g_MsgGlobalCtrl.Smsc[g_MsgGlobalCtrl.CurrSimId].pSmsc);
        g_MsgGlobalCtrl.Smsc[g_MsgGlobalCtrl.CurrSimId].pSmsc = NULL;
        g_MsgGlobalCtrl.Smsc[g_MsgGlobalCtrl.CurrSimId].pSmsc = Hal_Mem_Alloc(i + 1);
        Hal_Mem_Set(g_MsgGlobalCtrl.Smsc[g_MsgGlobalCtrl.CurrSimId].pSmsc, 0, i + 1);
        strcpy(g_MsgGlobalCtrl.Smsc[g_MsgGlobalCtrl.CurrSimId].pSmsc, g_MsgGlobalCtrl.pContact);
        strcpy(pSetSmscReq->pSmsc, g_MsgGlobalCtrl.pContact);

        MMI_Modem_Set_Smsc_Req(pSetSmscReq);
    }
    else
    {
        // 2s timer start
        Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_CENTRE_NUM_STATUS);
    }
    if (NULL != g_MsgGlobalCtrl.pContact)
    {
        Hal_Mem_Free(g_MsgGlobalCtrl.pContact);
        g_MsgGlobalCtrl.pContact = NULL;
    }
} /* Sms_Setting_Phone_Num_OK */

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Setting_Phone_Num_OK_Timeout(VOID* id)
{
    Nav_Forward(ACT_ID_MESSAGES_CENTRE_NUM_STATUS, ACT_ID_MESSAGES_SIM_SELECTION, NULL, NULL);
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Setting_Delivery_Report(lv_obj_t *pBtn,lv_event_t event)
{
    // sms setting delivery report call back function
    // create Messages_Sim_Selection_Status chart

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    UINT8                      *data   = Hal_Mem_Alloc(sizeof(SMS_NV_DELIVERY_REP) * NV_SMS_MAX_FLG_NUM);
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *pDeliveryRep = NULL;
    UI_Button_Desc_t           *ButtonList   = NULL;
    SMS_SIM_STATUS             SimStatus     = SMS_NO_SIM_PRESENT;

    pDeliveryRep = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(pDeliveryRep, 0, sizeof(UI_Normal_List_Only_Desc_t));

    ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 2);
    Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * 2);

    g_MsgGlobalCtrl.pChart = pDeliveryRep;

    UI_NV_Read_Req(NV_SECTION_UI_SMS, 1, NV_SMS_MAX_FLG_NUM, data);

    pDeliveryRep->TitleBar.TxtId      = PHONE_TEXT_ID_SIM_SEL;
    pDeliveryRep->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pDeliveryRep->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    SimStatus = Sms_Get_Sim_Status();
    if (SMS_SIM1_PRESENT == (SimStatus & SMS_SIM1_PRESENT))
    {
        pDeliveryRep->List.ListButtonCnt++;
    }
    if (SMS_SIM2_PRESENT == (SimStatus & SMS_SIM2_PRESENT))
    {
        pDeliveryRep->List.ListButtonCnt++;
    }
    if (pDeliveryRep->List.ListButtonCnt)
    {
        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * pDeliveryRep->List.ListButtonCnt);
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * pDeliveryRep->List.ListButtonCnt);
        pDeliveryRep->List.Index      = 0;
        pDeliveryRep->List.ButtonList = ButtonList;

        if (SMS_BOTH_SIM_PRESENT == SimStatus)
        {
            ButtonList[0].ButtonIndex = 0xFF;
            ButtonList[0].TxtId       = PHONE_TEXT_ID_SIM1;
            ButtonList[0].SymbolId1   = SYMBOL_SIM1;
            ButtonList[0].Valid       = true;
            ButtonList[0].ReleaseFun  = Sms_Setting_Sim_Select_Sts;
            if (MSG_DELIVERY_REP_YES == data[0])
            {
                if (UI_LANG_CH == lv_lang_act())                       /*0--En, 1--Ch*/
                {
                    ButtonList[0].SymbolId2 = SYMBOL_ON; // yes
                }
                else
                {
                    ButtonList[0].SymbolId2 = SYMBOL_ONEN;      // yes
                }
            }
            else
            {
                if (UI_LANG_CH == lv_lang_act())                        /*0--En, 1--Ch*/
                {
                    ButtonList[0].SymbolId2 = SYMBOL_OFF; // no
                }
                else
                {
                    ButtonList[0].SymbolId2 = SYMBOL_OFFEN;      // no
                }
            }

            ButtonList[1].ButtonIndex = 0xFF;
            ButtonList[1].TxtId       = PHONE_TEXT_ID_SIM2;
            ButtonList[1].SymbolId1   = SYMBOL_SIM2;
            ButtonList[1].Valid       = true;
            ButtonList[1].ReleaseFun  = Sms_Setting_Sim_Select_Sts;
            if (MSG_DELIVERY_REP_YES == data[1])
            {
                if (UI_LANG_CH == lv_lang_act())                       /*0--En, 1--Ch*/
                {
                    ButtonList[1].SymbolId2 = SYMBOL_ON; // yes
                }
                else
                {
                    ButtonList[1].SymbolId2 = SYMBOL_ONEN;      // yes
                }
            }
            else
            {
                if (UI_LANG_CH == lv_lang_act())                        /*0--En, 1--Ch*/
                {
                    ButtonList[1].SymbolId2 = SYMBOL_OFF; // no
                }
                else
                {
                    ButtonList[1].SymbolId2 = SYMBOL_OFFEN;      // no
                }
            }
        }
        else if (SMS_SIM1_PRESENT == SimStatus)
        {
            ButtonList[0].ButtonIndex = 0xFF;
            ButtonList[0].TxtId       = PHONE_TEXT_ID_SIM1;
            ButtonList[0].SymbolId1   = SYMBOL_SIM1;
            ButtonList[0].Valid       = true;
            ButtonList[0].ReleaseFun  = Sms_Setting_Sim_Select_Sts;
            if (MSG_DELIVERY_REP_YES == data[0])
            {
                if (UI_LANG_CH == lv_lang_act())                       /*0--En, 1--Ch*/
                {
                    ButtonList[0].SymbolId2 = SYMBOL_ON; // yes
                }
                else
                {
                    ButtonList[0].SymbolId2 = SYMBOL_ONEN;      // yes
                }
            }
            else
            {
                if (UI_LANG_CH == lv_lang_act())                        /*0--En, 1--Ch*/
                {
                    ButtonList[0].SymbolId2 = SYMBOL_OFF; // no
                }
                else
                {
                    ButtonList[0].SymbolId2 = SYMBOL_OFFEN;      // no
                }
            }
        }
        else if (SMS_SIM2_PRESENT == SimStatus)
        {
            ButtonList[0].ButtonIndex = 0xFF;
            ButtonList[0].TxtId       = PHONE_TEXT_ID_SIM2;
            ButtonList[0].SymbolId1   = SYMBOL_SIM2;
            ButtonList[0].Valid       = true;
            ButtonList[0].ReleaseFun  = Sms_Setting_Sim_Select_Sts;
            if (MSG_DELIVERY_REP_YES == data[1])
            {
                if (UI_LANG_CH == lv_lang_act())                       /*0--En, 1--Ch*/
                {
                    ButtonList[0].SymbolId2 = SYMBOL_ON; // yes
                }
                else
                {
                    ButtonList[0].SymbolId2 = SYMBOL_ONEN;      // yes
                }
            }
            else
            {
                if (UI_LANG_CH == lv_lang_act())                        /*0--En, 1--Ch*/
                {
                    ButtonList[0].SymbolId2 = SYMBOL_OFF; // no
                }
                else
                {
                    ButtonList[0].SymbolId2 = SYMBOL_OFFEN;      // no
                }
            }
        }
    }
    pDeliveryRep->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pDeliveryRep->BtnBar.ButtonR.Valid = true;

    if(SimStatus != SMS_NO_SIM_PRESENT)
    {
        pDeliveryRep->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
        pDeliveryRep->BtnBar.ButtonM.Valid = true;
    }
    else
    {
        pDeliveryRep->BtnBar.ButtonM.Valid = false;
    }

    pDeliveryRep->KeyFunc = Sms_Create_Opt_Handle;    // common

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Create_Send_To_Many_Create;
    FuncList.OnDestroy      = Sms_List_Only_Common_Destory;   // temp
    FuncList.OnSaveState    = Sms_Common_Save;                // temp
    FuncList.OnRestoreState = Sms_Create_Send_To_Many_Create; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_SIM_SELECTION_STATUS, &FuncList, (void *)pDeliveryRep);
} /* Sms_Setting_Delivery_Report */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Setting_Sim_Select_Sts(lv_obj_t *pBtn,lv_event_t event)
{
    // sms setting Delivery Report sim selection call back function
    // create Messages_Delivery_Report chart
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *pDeliveryRep = NULL;
    UI_Button_Desc_t           *ButtonList   = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pDeliveryRep = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(pDeliveryRep, 0, sizeof(UI_Normal_List_Only_Desc_t));

    ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 2);
    Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * 2);

    g_MsgGlobalCtrl.pChart    = pDeliveryRep;
    g_MsgGlobalCtrl.CurrSimId = (MMI_MODEM_SIM_ID)pBtn->user_data.user_num;// store the sim id

    pDeliveryRep->TitleBar.TxtId      = PHONE_TEXT_ID_SIM_SEL;
    pDeliveryRep->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pDeliveryRep->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    pDeliveryRep->List.ListButtonCnt = 2;
    pDeliveryRep->List.Index         = 0;
    pDeliveryRep->List.ButtonList    = ButtonList;

    ButtonList[0].ButtonIndex = 0;
    ButtonList[0].TxtId       = PHONE_TEXT_ID_YES;
    ButtonList[0].ReleaseFun  = Sms_Setting_Delivery_Rep;
    ButtonList[0].Valid       = true;

    ButtonList[1].ButtonIndex = 1;
    ButtonList[1].TxtId       = PHONE_TEXT_ID_NO;
    ButtonList[1].ReleaseFun  = Sms_Setting_Delivery_Rep;
    ButtonList[1].Valid       = true;

    pDeliveryRep->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pDeliveryRep->BtnBar.ButtonR.Valid = true;

    pDeliveryRep->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    pDeliveryRep->BtnBar.ButtonM.Valid = true;

    pDeliveryRep->KeyFunc = Sms_Create_Opt_Handle;    // common

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_List_Only_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;              // temp
    FuncList.OnRestoreState = Sms_Common_Restore;           // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DELIVERY_REPORT, &FuncList, (void *)pDeliveryRep);
    pDeliveryRep->List.ButtonList[0].Button->user_data.user_num = true;
    pDeliveryRep->List.ButtonList[1].Button->user_data.user_num = false;
} /* Sms_Setting_Sim_Select_Sts */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Setting_Delivery_Rep(lv_obj_t *pBtn,lv_event_t event)
{
    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    SMS_NV_DELIVERY_REP          *data            = (SMS_NV_DELIVERY_REP *)Hal_Mem_Alloc(sizeof(SMS_NV_DELIVERY_REP) * NV_SMS_MAX_FLG_NUM);
    MMI_Modem_Set_Delivery_Req_t *pSetDeliveryRep = NULL;
    Nav_Func_List_t              FuncList;
    UI_Status_Desc_t             *pDeliverySts = NULL;

    pDeliverySts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pDeliverySts, 0, sizeof(UI_Status_Desc_t));

    pDeliverySts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pDeliverySts->ContLabel.TxtId      = PHONE_TEXT_ID_DONE;
    pDeliverySts->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pDeliverySts->ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    pDeliverySts->ContImg.Img      = SYMBOL_CHECKED;
    pDeliverySts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pDeliverySts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_SEND_USING_STATUS, &FuncList, (void *)pDeliverySts);
    UI_NV_Read_Req(NV_SECTION_UI_SMS, 1, NV_SMS_MAX_FLG_NUM, (UINT8 *)data);
    pSetDeliveryRep = (MMI_Modem_Set_Delivery_Req_t *)Hal_Mem_Alloc(sizeof(MMI_Modem_Set_Delivery_Req_t));
    Hal_Mem_Set(pSetDeliveryRep, 0, sizeof(MMI_Modem_Set_Delivery_Req_t));
    if (true == pBtn->user_data.user_num)
    {
        pSetDeliveryRep->DeliveryRepFlg = MMI_MODEM_ENABLE;
        if (MMI_MODEM_SIM_1 == g_MsgGlobalCtrl.CurrSimId)
        {
            data[0] = MSG_DELIVERY_REP_YES;
        }
        else
        {
            data[1] = MSG_DELIVERY_REP_YES;
        }
    }
    else
    {
        pSetDeliveryRep->DeliveryRepFlg = MMI_MODEM_DISABLE;
        if (MMI_MODEM_SIM_1 == g_MsgGlobalCtrl.CurrSimId)
        {
            data[0] = MSG_DELIVERY_REP_NO;
        }
        else
        {
            data[1] = MSG_DELIVERY_REP_NO;
        }
    }
    pSetDeliveryRep->SimId = g_MsgGlobalCtrl.CurrSimId;

    MMI_Modem_Set_Delivery_Rep_Req(pSetDeliveryRep);
    UI_NV_Write_Req(NV_SECTION_UI_SMS, 1, NV_SMS_MAX_FLG_NUM, (UINT8 *)data);
    Hal_Mem_Free(data);
    data = NULL;
} /* Sms_Setting_Delivery_Rep */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Setting_No_Scrn(lv_obj_t *pBtn,lv_event_t event)
{
    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    // sms setting No. Scrning call back function
    // enter contacts function
    Contacts_Enter_Num_Scrn_List_Req();
}
